<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>核对仪器序列号</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../../../css/mui.min.css">
		<link rel="stylesheet" href="../../../css/global.css">
		<link rel="stylesheet" href="../../../css/style.css">
		<link href="../../../css/mui.picker.css" rel="stylesheet" />
		<link href="../../../css/mui.poppicker.css" rel="stylesheet" />
		<style type="text/css">
			.mui-btn {
				font-size: 16px;
				padding: 8px;
				margin: 3px;
			}
			h5.mui-content-padded {
				margin-left: 3px;
				margin-top: 20px !important;
			}
			h5.mui-content-padded:first-child {
				margin-top: 12px !important;
			}
			.ui-alert {
				text-align: center;
				padding: 20px 10px;
				font-size: 16px;
			}
			.details_con{
				margin: 0;
			}
			.btnBox button {
				line-height: 35px;
				border: 1px solid #666 !important;
				color: #333 !important;
			}
			.hdxlh{
				width: 80%;
				margin: 20px auto 0;
				height: 35px;
				line-height: 35px;
				background: #ea1e1a;
				font-size: 15px;
				color: #fff;
				text-align: center;
				border-radius: 20px;
			}
			.hdjg{
				width: 80%;
				margin: 0 auto;
				text-align: center;
				font-size: 15px;
				height: 60px;
				line-height: 60px;
			}
			.serialNumber .textArea{
				border-radius: 20px;
			}
			input.d_ipt{
				text-align: left;
				width: 65%;
			}
			.btn_box{
				
				overflow: hidden;
			}		
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">核对仪器序列号</h1>
		</header>
		<!-- html代码 start -->
		<div class="mui-content">
			<div class="details_con serialNumber">
				<div class="clum">
					<span class="name">仪器序列号</span>
					<input id="instrumentSerialNumber" type="text" class="d_ipt" placeholder="请输入仪器序列号" style="float: left;"/>
					<img src="../../../images/icon_384.png" style="float: right;width: 24px;margin-top: 15px;" id="smtxm">
				</div>
				<div class="btnBox" style="margin-top: 15px;height: auto;border-bottom: 0;">
					<div id="hdxlh" class="hdxlh">核对仪器序列号</div>
					<div class="hdjg">核对结果:<span id='showUserPicker'>尚未核对</span></div>
				</div>
				
				<div class="clum">
					<span class="name">仪器二维码</span>
					<input id="instrumentCode" type="text" class="d_ipt" placeholder="" style="float: left;"/>
					<img src="../../../images/icon_385.png" style="float: right;width: 24px;margin-top: 15px;" id="bdyqewm">
				</div>
		
				<p class="infoTit">其他变更信息</p>
				<div class="textArea">
					<textarea id="qtbgxx" style="font-size: 16px;"></textarea>
				</div>
			</div>
			<div class="btn_box">
				<span class="fl" id="cancel">跳过</span>
				<span class="fr red" id="save">保存</span>
			</div>
			<div style="height: 50px;"></div>
		</div>
		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<!-- 基础js end -->
		<script src="../../../js/sqliteTools.js"></script>
		<script src="../../../js/utils/rolldate.min.js"></script>
		<script src="../../../js/mui.picker.js"></script>
		<script src="../../../js/mui.poppicker.js"></script>
		
		<script type="text/javascript" charset="utf-8">
			var sign = false;
			
			var ServiceNoticeId;
			var serviceNo;
			var planId;
			var state;
			var listName;
			
			 //mui初始化
			(function($, doc) {
				$.init();
				
				//普通示例
				var userPicker = new $.PopPicker();
				userPicker.setData([{
					value: 'ywj',
					text: '不一致'
				}, {
					value: 'aaa',
					text: '一致'
				}]); 
				var showUserPickerButton = doc.getElementById('showUserPicker');
				var userResult = doc.getElementById('showUserPicker');
				/* showUserPickerButton.addEventListener('tap', function(event) {
					userPicker.show(function(items) {
						console.log(items[0].text)
						userResult.innerText = items[0].text;
						//返回 false 可以阻止选择框的关闭
						//return false;
					});
				}, false); */
			
				
			
				$.plusReady(function() {
					
					// 从上一个页面取值
					var self = plus.webview.currentWebview();
					 // 获取上一个页面传过来的参数并显示到页面
					 ServiceNoticeId = self.ServiceNoticeId;
					 serviceNo = self.serviceNo;
					 planId = self.planId;
					 state = self.state; 
					 logFlag = self.logFlag;
					 listName = self.listName;

					// 跳过方法
					h("#cancel").tap(function(){	
						app.closeWaiting();
						var qtbgxx = h("#qtbgxx").val();
						ajaxPost(BASE_URL + "cc/instrument/skipApply", {
							"enginnerId": app.getUser().enginnerId,
							"serviceNo": serviceNo,
							"remarks": qtbgxx,
							"parameter": h("#instrumentSerialNumber").val(),
							"type": "1",
							"dizhi":true,
							"jwd":false
						}, function(data) {
							app.closeWaiting();
							if(data.code==200){
								var checkedInList = plus.webview.getWebviewById('view/service/notice/checkedInList.html');
								if(checkedInList){
									checkedInList.evalJS('initData()')
								}
								
								var conductList = plus.webview.getWebviewById('view/service/assign/conductList.html');
								if(conductList){
									conductList.evalJS('getList()')
								}
								
								// 1、刷新FSE首页
								var indexFSE = plus.webview.getWebviewById('view/main/indexFSE.html');
								if(indexFSE){
									indexFSE.evalJS('getList("1")')
								}
								
								// 14、刷新工作台查询未关闭服务通知列表
								var notClosedList = plus.webview.getWebviewById('view/service/notice/notClosedList.html');
								if(notClosedList){
									notClosedList.evalJS('initData()')
								}
								
								if ((listName && listName == "infoUpdate") || (state && state == "log")){
									mui.back()
								} else {
									if ( logFlag && logFlag == 1){
										var signOutAddReport = plus.webview.create('/view/service/notice/signOutAddReport.html','view/service/notice/signOutAddReport.html',null,{
											ServiceNoticeId:ServiceNoticeId,
											serviceNo:serviceNo,
											planId:planId
										})
										signOutAddReport.show()
									}else {
										var signOut = plus.webview.create('/view/service/notice/signOut.html','view/service/notice/signOut.html',null,{
											ServiceNoticeId:ServiceNoticeId,
											serviceNo:serviceNo,
											planId:planId
										})
										signOut.show()
									}
								}
								self.close()
							} else {
								app.toast("申请失败");
							}
						}, function(errorMsg) {
							app.closeWaiting();
							console.log(JSON.stringify(errorMsg))
						});
					});
					
					// 保存
					h("#save").tap(function() {
						app.showWaiting('正在提交...')
						
						if(!sign){
							app.closeWaiting()
							app.toast("请核对仪器序列号");
							return
						}
						
						var qtbgxx = h("#qtbgxx").val();
						if (userResult.innerText == "一致"){
							h("#qtbgxx").val("");
							qtbgxx = '';
						} else {
							if(qtbgxx==undefined || qtbgxx==""){
								app.closeWaiting()
								app.toast("请填写变更信息")
								return
							}
						}

						ajaxPost(BASE_URL + "cc/instrument/updateApply", {
							"enginnerId": app.getUser().enginnerId,
							"serviceNo": serviceNo,
							"remarks": qtbgxx,
							"parameter": h("#instrumentSerialNumber").val(),
							"type": "1",
							"dizhi":true,
							"jwd":false
						}, function(data) {
							app.closeWaiting()
							if(data.code==200){
								var instrumentSerialNumber = h("#instrumentSerialNumber").val();
								var enginnerId = app.getUser().enginnerId;
								var sqliteTool = new sqliteTools(); 								
								sqliteTool.openDatabase();
								sqliteTool.selectServiceByPlanId(enginnerId, planId, '', function(flag, offlineData, callBackData) {
									if (offlineData && offlineData.length > 0) {
										sqliteTool.insertServiceCollateData(offlineData[0].id, instrumentSerialNumber, function(flag) {
											console.log("更新核对"+flag)
										})
									} else {
										sqliteTool.closeDB();
									}										
								});
								
								if (qtbgxx && qtbgxx != '') {
									app.toast("申请成功");
								}
								var checkedInList = plus.webview.getWebviewById('view/service/notice/checkedInList.html');
								if(checkedInList){
									checkedInList.evalJS('initData()')
								}
								
								var conductList = plus.webview.getWebviewById('view/service/assign/conductList.html');
								if(conductList){
									conductList.evalJS('getList()')
								}
								
								// 1、刷新FSE首页
								var indexFSE = plus.webview.getWebviewById('view/main/indexFSE.html');
								if(indexFSE){
									indexFSE.evalJS('getList("1")')
								}
								
								// 14、刷新工作台查询未关闭服务通知列表
								var notClosedList = plus.webview.getWebviewById('view/service/notice/notClosedList.html');
								if(notClosedList){
									notClosedList.evalJS('initData()')
								}
															
								if ((listName && listName == "infoUpdate") || (state && state == "log")){
									mui.back()
								} else {
									if ( logFlag && logFlag == 1){
										var signOutAddReport = plus.webview.create('/view/service/notice/signOutAddReport.html','view/service/notice/signOutAddReport.html',null,{
											ServiceNoticeId:ServiceNoticeId,
											serviceNo:serviceNo,
											planId:planId
										})
										signOutAddReport.show()
									}else {
										var signOut = plus.webview.create('/view/service/notice/signOut.html','view/service/notice/signOut.html',null,{
											ServiceNoticeId:ServiceNoticeId,
											serviceNo:serviceNo,
											planId:planId
										})
										signOut.show()
									}
								}									
								
								self.close()
							}else{
								app.toast("保存失败");
							}
						}, function(errorMsg) {
							app.closeWaiting()
							console.log(JSON.stringify(errorMsg))
						});
						
					});
					
					
					// 扫描条形码
					h("#smtxm").tap(function(){
						app.jumpTo("/view/barcode/barcode.html","view/barcode/barcode.html",{
							"state": 1
					    })
					});
					
					// 核对仪器序列号
					h("#hdxlh").tap(function(){
						app.showWaiting('正在提交...')
						var instrumentSerialNumber = h("#instrumentSerialNumber").val();
						if(instrumentSerialNumber==undefined || instrumentSerialNumber==""){
							app.closeWaiting()
							app.toast("请输入仪器序列号");
							return
						}
						ajaxGet(BASE_URL + "cc/instrument/checkSerialNumber", {
							"ServiceNoticeId": ServiceNoticeId,
							"serialNumber": h("#instrumentSerialNumber").val()
						}, function(data) {
							app.closeWaiting()
							sign = true;

							if (data.code == 200) {
								userResult.innerText = "一致";
								h("#qtbgxx").val("");
							}else if(data.code == 201){
								userResult.innerText = "不一致";
								h("#qtbgxx").val("仪器序列号不一致，新的仪器序列号为："+instrumentSerialNumber);
							}
						}, function(errorMsg) {
							app.closeWaiting()
							console.log(JSON.stringify(errorMsg))
						});
					});
					
					// 绑定仪器二维码 调用扫码方法
					h("#bdyqewm").tap(function(){
						app.jumpTo("/view/barcode/barcode.html","view/barcode/barcode.html",{
							"state": 2
						})
					});

					/* h('.mui-action-back').tap(function () {
						pageReload()
					}) */
					
					
				});
				
		
				
			}(mui, document));
			
			// 扫描条形码回调方法
			function scaned(type, code, file, state) {
				console.log(state)
				console.log(type)
				console.log(code)
				console.log(file)
				// 扫描条形码
				if(state==1){
					h("#instrumentSerialNumber").val(code)
				}
				// 绑定仪器二维码
				else if(state==2){
					h("#instrumentCode").val(code)
					ajaxGet(BASE_URL + "cc/instrument/bindingQrCode", {
						"ServiceNoticeId": ServiceNoticeId,
						"QrCode": code,
						"EnginnerId": app.getUser().enginnerId
					}, function(data) {
						console.log(JSON.stringify(data))
						if (data.code == 200) {
							app.toast("扫描成功")
						}else{
							app.toast("扫描失败")
						}
					}, function(errorMsg) {
						console.log(JSON.stringify(errorMsg))
					});
				}
				
			}

			//返回刷新已签到服务列表和进行中列表的刷新
			/* function pageReload() {
				// alert(1)
				var checkedInList= plus.webview.getWebviewById('view/service/notice/checkedInList.html');
				var conductList = plus.webview.getWebviewById('view/service/assign/conductList.html');
				checkedInList&&checkedInList.evalJS('initData()')
				conductList&&conductList.evalJS('getList()')
			} */
			
		</script>
		<!-- js代码 end -->

	</body>

</html>
